import { Injectable } from '@nestjs/common';
import { fa_cms_special } from '../../entities/fa_cms_special';
import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { PaginationVo } from '../../common/pagination.vo';

@Injectable()
export class SpecialService {
  constructor(@InjectRepository(fa_cms_special) private readonly repository: Repository<fa_cms_special>) {}

  async findOneById(id: number) {
    return await this.repository.findOne(id);
  }

  async findWithPagination(page: number, pageSize: number): Promise<PaginationVo<fa_cms_special>> {
    const query = this.repository.createQueryBuilder();
    const [data, totalCount] = await query.limit(pageSize).skip((page - 1) * pageSize).getManyAndCount();
    return {
      data,
      pageInfo: {
        totalCount,
        page,
        pageSize,
      },
    };
  }
}
